package org.point.service.impl;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import org.point.common.service.impl.BaseServiceImpl;
import org.point.common.util.DoPage;
import org.point.dao.ProductDao;
import org.point.dao.ProductInOutDao;
import org.point.dao.impl.ProductInOutDaoImpl;
import org.point.domain.ProductInOut;
import org.point.domain.ProductType;
import org.point.service.ProductInOutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 
 * @ClassName: ProductInOutServiceImpl  
 * @Description: TODO(商品进出业务实现类)  
 * @author Kenny_Z' szqiuk@gmail.com
 * @date 2016年10月23日 下午4:02:01  
 *
 */
@Service("productInOutService")
public class ProductInOutServiceImpl extends BaseServiceImpl<ProductInOut, Serializable> implements ProductInOutService {
	
	@Autowired
	private ProductInOutDao dao;
	@Autowired
	private ProductDao prodao;

	public DoPage<ProductInOut> searchPIOInfo(DoPage<ProductInOut> page) {
		List<ProductInOut> records = dao.searchPIOInfo(page);
		Integer totalRecords = dao.searchPIOCount(page);
		page.setList(records);
		page.setTotalRecords(totalRecords);
		return page;
	}

	/**
	 * 新增商品进出信息
	 */
	public Integer insertPIO(ProductInOut record ,String pio_code) {
		Integer result = 0;
		Map<String, Object> map = new HashMap<String, Object>();
		if(record.getId()!=null){
			map.put("newIDs", record.getId());
			Integer del  = dao.delPIO(map);
			Integer insert  = dao.insertPIO(record);
			if(insert+del>1){
				result = 1;
		    }
		}else{
			record.setStatus(new Byte("1"));
			record.setProductInOutId(pio_code);
			result = dao.insertPIO(record);
		}
		return result;
	} 
	
	public Integer deletePIOs(Map<String, Object> map) {
		Integer result =0;
		try {
			result = dao.delPIO(map);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	public ProductInOut searchForId(Map<String, Object> map) {
		// TODO 根据商品ID查找
		return dao.searchForId(map);
	}

	public List<Hashtable<Object, Object>> getProducts() {
		List<Hashtable<Object, Object>> record = prodao.selectAllProduct();
		return record;
	}
}
